package com.epam.tcs.dao.hibernate.entities;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = "tcs_program")
public class Program  implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5538259398700780225L;
	private long program_id;
	private String name;
	private String description;
	private int hours;

	private List<Theme> themes;
	private List<Group> groups;

	public Program(){}
	
	public Program(String name, String description, int hours,
			List<Theme> themes, List<Group> groups) {
		this.name = name;
		this.description = description;
		this.hours = hours;
		this.themes = themes;
		this.groups = groups;
	}

	@Id
	@Column(name = "program_id", length = 4)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getProgram_id() {
		return program_id;
	}

	public void setProgram_id(long program_id) {
		this.program_id = program_id;
	}

	@Column(name = "name", length = 20)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "hours", length = 4)
	public int getHours() {
		return hours;
	}

	public void setHours(int hours) {
		this.hours = hours;
	}

	// many to many with tcs_theme

//	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
	@JoinTable(name = "tcs_program_theme", joinColumns = { @JoinColumn(name = "program_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "theme_id", nullable = false, updatable = false) })
	public List<Theme> getThemes() {
		return themes;
	}

	public void setThemes(List<Theme> themes) {
		this.themes = themes;
	}

//	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "program")
	@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, mappedBy = "program")
	public List<Group> getGroups() {
		return groups;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}
}
